<template>
	<view class="page-body">

		<cu-custom bgColor="" :isBack="true">
			<block slot="backText" class="titilestyle">{{title}}</block>

		</cu-custom>
		<Loading class="loading-box" v-show="!isLoading" :isStatus='loadStatus'></Loading>

		<scroll-view scroll-y="true" :style="{height: swiperHeight+'px'}" style="background-color: #EEEEEE;">


			<view class="oi-detail" :style="{height: swiperHeight+'px'}">
				<view class="oi-header">
					<view class="os-nav">
						<view class="middle" :class="{'hov':navIndex==0}" @click="changeNav(0)">配送上寝</view>
						<view class="middle" :class="{'hov':navIndex==1}" @click="changeNav(1)">到店自取</view>
					</view>
					<view class="os-outward" :class="{'os-active':navIndex==0}">
						<view class="os-add-address middle" v-if="address.addres_id == 0" @click="addAddress">
							+ 新增地址
						</view>
						<view class="os-address" v-else @click="selectAddr">
							<view>
								<image :src="domain+'/TakeOut/static/cefimgs/location_blue@2x.png'" class="loc-ico">
								</image>
							</view>
							<view class="address">
								<view style="width: 100%;">
									<view>
										<text
											class="address-name">{{shopInfo.area.area_name?shopInfo.area.area_name+"-":""}}{{address.address+address.detail || ''}}</text>
									</view>

									<view class="consigneebox">
										<view class="consignee">{{address.consignee || ''}}</view>
										<view class="mobile1">{{address.mobile || ''}}</view>

									</view>
								</view>
								<image :src="domain+'/TakeOut/static/cefimgs/arrowright_gray@3x.png'"
									class="os-right-ico"></image>
							</view>
						</view>
						<view class="os-time  ">
							<view class=" " style="height: 80upx;display: flex;align-items: center;">
								<image :src="domain+'/TakeOut/static/cefimgs/time_ico.png'" class="os-time-ico"></image>
							</view>
							<picker mode="time" :value="cartInfo.estimate_time" :start="cartInfo.estimate_time"
								:end="pick_end_time" @change="appointment" @cancel="cancelReserve"
								style="width: 90%;height: 100%;">
								<view class="timeinfo ">
									<view class="time-item " v-if="postData.is_reserve == 0">
										<text class="time-item-tit ">立即送出</text><text
											class="expect-time ">预计{{cartInfo.estimate_time || "未选择"}}送达</text>
									</view>
									<view class="time-item " v-else>
										<text class="time-item-tit">指定时间：</text><text
											class="expect-time">{{postData.reserve_time ||  "未选择"}}送达</text>
									</view>
									<image :src="domain+'/TakeOut/static/cefimgs/arrowright_gray@3x.png'"
										class="os-right-ico">
									</image>
								</view>
							</picker>
						</view>

					</view>

					<view class="os-self" :class="{'os-active':navIndex==1}">
						<view class="os-self-item">
							<view class="os-self-tit"><text>姓名：</text></view><input type="text"
								:value="postData.consignee" placeholder="请输入取餐姓名" />
						</view>
						<view class="os-self-item">
							<view class="os-self-tit"><text>电话：</text></view><input type="text" :value="postData.mobile"
								placeholder="请输入取餐电话" />
						</view>
						<view class="os-self-item">
							<picker mode="time" :value="cartInfo.estimate_time" :start="cartInfo.estimate_time"
								:end="pick_end_time" @change="appointment" @cancel="cancelReserve">
								<view class="flex justify-between">
									<text>预约时间：{{postData.reserve_time || '已在店内'}} </text>
									<text class="cuIcon-right"></text></text>
								</view>
							</picker>
						</view>
					</view>
				</view>
				<view class="oi-goods">
					<view class="oi-shop-info" v-if="shopInfo.logo">
						<image mode="aspectFill" :src="shopInfo.logo" class="oi-shop-logo" @error="errorLogo"></image>
						<view class="oi-shop-title"><text>{{shopInfo.shop_name}}</text></view>
					</view>
					<view class="line-gray" v-if="shopInfo.logo">

					</view>

					<view class="oi-fee-item">
						<text class="tit">文件页数</text>
						<input class="uni-input text-right" type="number" placeholder="请输入打印的页数" v-model="pages" />
						<!-- <text>6页</text> -->
					</view>
					<view class="oi-fee-item">
						<text class="tit">单页价格</text>
						<text>{{cartInfo.price || 0}}元/页</text>
					</view>
					<view class="oi-fee-item">
						<text class="tit">打印份数</text>
						<view class="fr  water-item-right">
							<yp-number-box min="0" :value="1" :index="1" @change="cart">
							</yp-number-box>
						</view>
					</view>


					<view class="oi-fee-item">
						<text class="tit">配送费</text>
						<text v-if="cartInfo.delivery_fee==0">免配送费</text><text
							v-else>￥{{cartInfo.delivery_fee || 0}}</text>
					</view>

					<view class="oi-fee-item text-red" v-if="cartInfo.full_money > 0">
						<text class="tit tit-box">满减</text>
						<text class="minusfee">-￥{{cartInfo.full_money || 0}}</text>
					</view>
					<view class="oi-fee-item text-red" v-if="cartInfo.first_money > 0">
						<text class="tit tit-box">首单</text>
						<text class="minusfee">-￥{{cartInfo.first_money || 0}}</text>
					</view>
					<view class="oi-fee-item text-red" v-if="cartInfo.gift">
						<text class="tit tit-box">赠送</text>
						<text class="minusfee">{{cartInfo.gift || '--'}}</text>
					</view>
				</view>


				<view class="oi-deduct">
					<!-- 	<view class="oi-deduct-item">
						<text class="tit">使用余额</text>
						<view>
							<text class="minusfee" v-if="cartInfo.user_money > 0">-￥{{cartInfo.user_money || 0}}</text>
							<text class="use-able" v-else>共有￥{{userInfo.money|numFilter}}</text>
							<label style="margin-left: 15rpx; padding-right: 0;">
								<checkbox-group @change="useMoney">
									<checkbox class="round" value="user_money" color="#000000"
										style="transform:scale(1)"
										:disabled="cartInfo.online_amount==0 && is_use_money==0" />
								</checkbox-group>
							</label>
						</view>
					</view>
					<view class="oi-deduct-item">
						<text class="tit">使用积分</text>
						<view>
							<text class="minusfee"
								v-if="cartInfo.integral_money > 0">-￥{{cartInfo.integral_money || 0}}</text>
							<text class="use-able" v-else>共有{{userInfo.integral || 0 }}</text>
							<checkbox-group @change="useIntegral">
								<label style="margin-left: 15rpx; padding-right: 0;">
									<checkbox class="round" value="Integral" color="#000000" style="transform:scale(1)"
										:disabled="cartInfo.online_amount==0 && is_use_integral==0" />
								</label>
							</checkbox-group>
						</view>
					</view>
				 -->

					<view class="oi-deduct-item" @click="selectCoupon">
						<text class="tit">优惠券</text>
						<view class="coupon-rig" style="text-align: right;margin-right: 10upx;">
							<text class="coupon-num" v-if="cartInfo.coupon_price==0">可用{{couponList.length}}张</text>

							<text v-else class="minusfee">-￥{{cartInfo.coupon_price || 0}}</text>

							<image :src="domain+'/TakeOut/static/cefimgs/arrowright_gray@3x.png'"
								class="os-right-ico-small">

							</image>

						</view>
					</view>
					<view class="line-gray">

					</view>
					<view class="oi-deduct-item" @click="selectCoupon">
						<text class="tit-style ">应付款</text>
						<view class="coupon-rig" style="text-align: right;margin-right: 10upx;">
							<!-- 	<text class="total-prom">已抵扣￥{{cartInfo.deduct_money || 0}}</text> -->
							<text class="total-price tit-style">￥{{doVal(cartInfo.total_price) || 0}}</text>
						</view>
					</view>

				</view>
				<view class="os-pay">
					<view class="os-pay-item">
						<view class="os-pay-list">
							<radio-group @change="checkPay" style="width: 100%;height: 100%;">
								<!-- #ifdef H5 -->
								<view class="os-pay-item">
									<view class="os-pay-left">
										<image :src="domain+'/TakeOut/static/cefimgs/pay-wechat-ico.png'"
											class="os-pay-ico"></image>
										<text>微信</text>
									</view>
									<label class="radio">
										<radio value="wxgzh" color="#09BB07" name="paycode"
											:checked="postData.pay_code == 'wxgzh'" />
									</label>
								</view>

								<!-- #endif -->
								<!-- #ifdef MP-WEIXIN -->
								<view class="os-pay-item ">
									<view class="os-pay-left ">
										<image :src="domain+'/TakeOut/static/cefimgs/pay-wechat-ico.png'"
											class="os-pay-ico"></image>
										<text>微信支付</text>
									</view>
									<label class="radio paySelect" style="padding-right: 0;">
										<radio value="wxpay" color="#09BB07" name="paycode"
											:checked="postData.pay_code == 'wxpay'" />
									</label>
								</view>
								<!-- #endif -->
								<!-- #ifdef APP-PLUS -->
								<view class="os-pay-item">
									<text>微信</text>
									<label class="radio">
										<radio value="wxpayApp" name="paycode"
											:checked="postData.pay_code == 'wxpayApp'" />
									</label>
								</view>
								<view class="os-pay-item">
									<text>支付宝</text>
									<label class="radio">
										<radio value="alipay" name="paycode" :checked="postData.pay_code == 'alipay'" />
									</label>
								</view>
								<!-- #endif -->
							</radio-group>
						</view>
					</view>
				</view>


				<view class="basis-xll middle text-blue text-bold margin-top-sm text-sm" v-if="postData.files"
					@click="preview">
					<view class="cuIcon-attentionfavorfill margin-right-sm "></view> 打印预览
				</view>
				<view class="v-block"></view>

				<uni-popup ref="address" type="center">
					<view class="" @tap="closeAddress">
						<view style="width: 640rpx; background: #F6F6F6; border-radius: 20rpx; padding-bottom: 20rpx;"
							@tap.stop="">
							<radio-group @change="checkAddress" style="width: 640rpx;height: 100%;position: relative;">
								<scroll-view class="addr-address-list" scroll-y="true"
									style="width: 94%; height: 600rpx;margin-left: 3%;">
									<view v-for="(item,index) in addressList" :key="index" class="addr-address-box ">
										<view class="addr-address-item1">
											<view class="text-bold" style="font-size: 28upx;">
												<text class="address ">{{item.address+item.detail}}</text>
												<text class="is_default" v-if="item.is_default==1">（默认）</text>

											</view>
											<view class="dizhi-info" style="color: #999999;">
												<text class="consignee">{{item.consignee}}</text>
												<text class="mobile ">{{item.mobile}}</text>
											</view>
										</view>
										<view class="addr-address-item2 middle">
											<label class="radio">
												<radio :value="item.address_id"
													:checked="item.address_id == postData.address_id" color="#1270E0"
													style="transform:scale(0.8)" />
											</label>
										</view>
									</view>
								</scroll-view>
							</radio-group>
							<view class="os-add-addr-btn" @click="addAddress">
								<text>+ 新增地址</text>
							</view>
						</view>
					</view>

				</uni-popup>


			</view>
		</scroll-view>

		<uni-popup ref="previewImg">
			<view class="middle preview-box " @tap="closePreview()">
				<image :src="postData.files" mode="aspectFit" class=" bg-white" @tap.stop=""></image>
				<view class="cuIcon-close text-white text-bold" style="font-size: 48rpx;" @click="closePreview()">
				</view>
			</view>

		</uni-popup>

		<view class="sub-pay-box animation-slide-bottom">
			<text class="text-xl text-bold">
				共 <text class="text-blue padding">￥{{doVal(cartInfo.total_price) || 0}}</text>元</text>
			<button class="cu-btn bg-blue lg zhifu" @click="subOrder">去支付</button>

		</view>


	</view>
</template>

<script>
	import ypNumberBox from "@/components/yp-number-box/yp-number-box.vue";
	import uniPopup from "@/uni_modules/uni-popup/components/uni-popup/uni-popup.vue";
	export default {
		components: {
			uniPopup,
			ypNumberBox

		},
		data() {
			return {
				domain: this.resDomain,
				title: "确认订单",
				shop_id: 0,
				navIndex: 0,
				payname: '微信',
				cartInfo: {},
				shopInfo: {
					area: {}
				},
				isLoading: false, //是否加载完成显示
				loadStatus: 'load',
				userInfo: {},
				pick_end_time: '23:59',
				couponList: {},
				curCoupon: -1,
				is_downstairs1: -1,
				postData: {
					'shop_id': 0,
					'address_id': 0,
					'is_reserve': 0,
					'reserve_time': null,
					'take_self': 0,
					'user_note': null,
					'origin_type': 0,
					'coupon_list_id': 0,
					'integral': 0,
					'user_money': 0,
					'step': 1,
					'pay_code': 'wxpay',
					'num': 1, //默认页数
					'copies': 1, //默认打印份数
					'device_id': -1, //设备id
					'price_id': '', ///价格id
					'files': '',
				},
				pages: 1,
				is_use_money: 0,
				is_use_integral: 0,
				address: {
					'addres_id': 0
				},
				addressList: {},
				orderInfo: {},
				is_sub: 0,
				wxconfig: null,
				swiperHeight: 0,
				downstairs_fee: 0,
				is_downstairs: 0,
			}
		},
		filters: {
			numFilter(value) {
				return parseFloat(value)
			}
		},
		watch: {
			pages(val) {
				this.postData.num = val;
				this.getData();
			}
		},
		onLoad(option) {


			(option.postInfo) ? (() => {
				let opt = JSON.parse(option.postInfo);
				this.postData.shop_id = opt.shop_id;
				this.postData.device_id = opt.device_id;
				this.postData.price_id = opt.price_id;
				this.postData.files = opt.url;



			})() : (() => {
				uni.showModal({
					title: "提示",
					content: "添加失败，请重试",
					showCancel: false,
					success: (e) => {
						uni.navigateBack({
							delta: 1,
						})
					}
				})
			})();
			this.apiRequest('/buyer/addressList', {
				area_id: uni.getStorageSync('area_id'),
			}).then(res => {
				this.addressList = res.data;
				if (this.addressList.length > 0) {
					for (var key in this.addressList) {
						if (this.addressList[key].is_default == 1) {
							this.address = this.addressList[key]
						}
					}
					if (this.address.addres_id == 0) { //没有默认地址，就选最新的地址
						this.address = this.addressList[0];
					}
					this.postData.address_id = this.address.address_id
					this.postData.consignee = this.address.consignee
					this.postData.mobile = this.address.mobile;
					this.getData();
				}
			})

		},
		onShow() {
			//获取优惠券
			this.apiRequest('/buyer/couponList', {
				area_id: uni.getStorageSync('area_id'),
				condtion: this.cartInfo.total_goods_price,
				status: "usable",
				shop_id: this.postData.shop_id,
				type: 1
			}).then(res => {
				this.couponList = res.data.data;
			})
			this.apiRequest('/buyer/userInfo', {
				area_id: uni.getStorageSync('area_id'),
			}).then(res => {
				this.userInfo = res.data
			})
		},
		mounted() {
			this.isLoading = true;
			uni.setStorageSync("selectCoun", "");
			this.getInfo().then((e) => {
				this.swiperHeight = e.screenHeight - (e.custom.top + e.custom.height) - 50;
			});

			//获取oppenid
			uni.login({

			})


		},
		methods: {
			isPeisong() {

			},
			doVal(val) {
				val = parseFloat(val);
				return val.toFixed(2);
			},
			cart(e) {
				this.postData.copies = e.num;
				this.getData();
			},
			errorLogo() {
				this.$nextTick(() => {
					this.shopInfo.logo = this.domain + "/static/img/error.png";
				})
			},
			errorGood(index) {
				this.cartInfo.goodsList[index].goods_thumbs = this.domain + "/static/img/error.png";
				this.$set(this.cartInfo.goodsList, index, this.cartInfo.goodsList[index]);
			},
			upData1: function() {
				this.updateAdree();
			},
			upData(index) {
				let selectCoun = uni.getStorageSync("selectCoun");
				if (selectCoun > -1) {
					this.postData.coupon_list_id = selectCoun;
					this.getData();
				} else if (selectCoun == -1) {
					this.cancelCoupon();
				} else {
					uni.setStorageSync("selectCoun", 0);
					this.postData.coupon_list_id = 0;
				}
			},
			changeNav(i) {
				this.navIndex = i;
				this.postData.take_self = i;
				this.postData.is_reserve = 0;
				this.postData.reserve_time = null;
				this.getData()
			},
			selectPay() {
				this.$refs.pay.open()
			},
			checkPay(e) {
				this.postData.pay_code = e.target.value
				this.$refs.pay.close();
			},
			addNote() {
				this.$refs.note.open()
			},
			bindTextAreaBlur(e) {
				this.postData.user_note = e.detail.value;
			},
			selectCoupon() {
				if (this.couponList.length == 0) {
					return;
				}
				let params = {
					shop_id: this.shop_id,

				}
				uni.navigateTo({
					url: "/pages/user/coupon?shop_id=" + this.shop_id + "&type=1&id=" + this.postData
						.coupon_list_id
				})
			},
			useIntegral(e) {
				if (e.detail.value.includes('Integral')) {
					this.postData.integral = this.userInfo.integral
					if (this.userInfo.integral > this.cartInfo.online_amount * 200) {
						this.postData.integral = this.cartInfo.online_amount * 200
					}
					this.is_use_integral = 1
				} else {
					this.postData.integral = 0
					this.is_use_integral = 0
				}
				this.getData()
			},
			useMoney(e) {
				if (e.detail.value.includes('user_money')) {
					this.postData.user_money = this.userInfo.money
					if (this.postData.user_money > this.cartInfo.online_amount * 100) {
						this.postData.user_money = this.cartInfo.online_amount * 100
					}
					this.is_use_money = 1
				} else {
					this.postData.user_money = 0
					this.is_use_money = 0
				}
				this.getData()
			},
			useMethod(e) {
				let val = e.detail.value;
				this.postData.is_downstairs = e.detail.value;
				this.is_downstairs1 = e.detail.value;
				this.getData();
			},
			selectAddr() {
				this.$refs.address.open()
			},
			checkAddress(e) {
				for (var key in this.addressList) {
					if (e.detail.value == this.addressList[key].address_id) {
						this.address = this.addressList[key]
						this.postData.address_id = e.detail.value;
						this.isPeisong();
					}
				}
				this.$refs.address.close();
			},
			addAddress() { //新增地址
				uni.navigateTo({
					url: '/app/TakeOut/pages/user/addressEdit?shop_id=' + this.shop_id
				});
			},
			appointment(e) {
				this.postData.reserve_time = e.detail.value
				this.postData.is_reserve = 1
			},
			cancelReserve() { //取消预约
				this.postData.reserve_time = null
				this.postData.is_reserve = 0
			},
			getData() { //获取最新价格
				this.apiRequest('/buyer/getPrice', this.postData).then(res => {
					if (res.code != 200) {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
						return
					}
					this.cartInfo = res.data
				})
			},
			subOrder() {
				this.postData.step = 2
				if (this.is_sub == 1) {
					uni.showToast({
						title: '订单已提交,请不要重复提交',
						icon: 'none'
					})
					setTimeout(function(e) {
						uni.redirectTo({
							url: '/app/CloudPrint/pages/order/order?order_id=' + this.orderInfo.order_id
						});
					}, 1000)
					return
				}
				this.is_sub = 1
				this.apiRequest('/buyer/addPrOrder', this.postData, 1).then(res => {
					if (res.code != 200) {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
						this.is_sub = 0
						return
					}
					//清理购物车数据
					uni.removeStorageSync('cartList-' + this.shop_id)
					uni.removeStorageSync('cartInfo-' + this.shop_id)
					uni.removeStorageSync('cartGoodsNum-' + this.shop_id)
					//this.orderInfo = res.data;
					this.orderPay = res.data;
					this.orderInfo.order_id = res.data.order_id;
					//this.getOrderInfo() //发起支付		
					this.requestPay(this.orderInfo.pay_code);
				})
			},
			getOrderInfo() {
				uni.showLoading({
					title: "请求中..."
				});
				var that = this
				if (this.postData.pay_code == 'alipayMobile') {
					window.location.href = this.apiHost + "/mobile/payment/alipayMobile?order_id=" + this.orderInfo
						.order_id
				} else {
					this.apiRequest('/mobile/Payment/payApp', this.orderInfo).then(res => {
						this.orderPay = res.data;
						if (res.code != 200) {
							uni.hideLoading();
							this.subscribe('order').then(r => {
								uni.redirectTo({
									url: '/app/CloudPrint/pages/order/order?order_id=' + that
										.orderInfo
										.order_id
								});
							})
						} else {
							this.requestPay(this.orderInfo.pay_code)
						}
					})
				}

			},
			requestPay(type = 'wxpay') {
				var that = this
				//#ifdef H5
				if (type == 'wxgzh') {
					var jweixin = require('jweixin-module')
					jweixin.config({
						debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
						appId: this.wxconfig.appId, // 必填，公众号的唯一标识
						timestamp: this.wxconfig.timestamp, // 必填，生成签名的时间戳
						nonceStr: this.wxconfig.nonceStr, // 必填，生成签名的随机串
						signature: this.wxconfig.signature, // 必填，签名，见附录1
						jsApiList: ['chooseWXPay'] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
					});

					var payInfo = this.orderPay
					jweixin.ready(function() {
						jweixin.chooseWXPay({
							timestamp: payInfo.timeStamp,
							nonceStr: payInfo.nonceStr,
							package: payInfo.package, // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=***）
							signType: payInfo.signType,
							paySign: payInfo.paySign, // 支付签名
							success: function(res) {
								uni.redirectTo({
									url: '/app/CloudPrint/pages/order/order?order_id=' + that
										.orderInfo
										.order_id
								});
							},
							cancel: function(res) {
								uni.redirectTo({
									url: '/app/CloudPrint/pages/order/order?order_id=' + that
										.orderInfo
										.order_id
								});
							},
							fail: function(res) {
								uni.redirectTo({
									url: '/app/CloudPrint/pages/order/order?order_id=' + that
										.orderInfo
										.order_id
								});
							}
						});
					});

					jweixin.error(function(res) {
						uni.redirectTo({
							url: '/app/CloudPrint/pages/order/order?order_id=' + this.orderInfo.order_id
						});
					})
				}

				//#endif


				// #ifndef H5  
				//支付宝支付
				if (type == 'alipay') {
					uni.requestPayment({ //订单提交成功，发起支付
						provider: 'alipay',
						orderInfo: this.orderPay, //微信、支付宝订单数据
						success: function(res) {
							console.log('success:' + JSON.stringify(res));
							uni.redirectTo({
								url: '/app/CloudPrint/pages/order/orde?order_id=' + this.orderInfo
									.order_id
							});
						},
						fail: function(err) {
							console.log('fail:' + JSON.stringify(err));
							uni.redirectTo({
								url: '/app/CloudPrint/pages/order/order?order_id=' + this.orderInfo
									.order_id
							});
						}
					});
				}
				//微信支付
				if (type == 'wxpay') {
					uni.requestPayment({ //订单提交成功，发起支付
						provider: 'wxpay',
						appId: this.orderPay.appId,
						timeStamp: String(this.orderPay.timeStamp),
						nonceStr: this.orderPay.nonceStr,
						package: this.orderPay.package,
						signType: this.orderPay.signType,
						paySign: this.orderPay.paySign,
						success: (res) => {
							uni.hideLoading();
							this.subscribe('order').then(r => {
								uni.redirectTo({
									url: '/app/CloudPrint/pages/order/orderInfo?order_id=' +
										that.orderInfo
										.order_id
								});
							})

						},
						fail: function(err) {
							uni.hideLoading();
							uni.redirectTo({
								url: '/app/CloudPrint/pages/order/orderInfo?order_id=' + that.orderInfo
									.order_id
							});
						}
					});
				}
				// #endif 
			},
			isWeiXin() { //判断是否微信浏览器
				var ua = window.navigator.userAgent.toLowerCase();
				if (ua.match(/MicroMessenger/i) == 'micromessenger') {
					return true;
				} else {
					return false;
				}
			},
			updateAdree() {
				this.apiRequest('/buyer/addressList', {
					area_id: uni.getStorageSync('area_id'),
				}).then(res => {
					this.addressList = res.data
					if (this.addressList.length > 0) {
						for (var key in this.addressList) {
							if (this.addressList[key].is_default == 1) {
								this.address = this.addressList[key]
							}
						}
						if (this.address.addres_id == 0) { //没有默认地址，就选最新的地址
							this.address = this.addressList[0]
						}
						this.postData.address_id = this.address.address_id
						this.postData.consignee = this.address.consignee
						this.postData.mobile = this.address.mobile;
						this.getData();

					}
				})

			},
			//预览打印图
			preview() {
				this.$refs.previewImg.open();
			},
			closeAddress() {
				this.$refs.address.close();
			},
			closePreview() {
				this.$refs.previewImg.close();
			}



		},
	}
</script>

<style>
	view {
		line-height: 1.8;
	}

	.line-gray {
		width: 100%;
		height: 1upx;
		background-color: #EEEEEE;
		opacity: 0.4;
		margin: 20upx 0 20upx 0;
	}

	.oi-detail {
		width: 94%;
		margin-left: 3%;
		height: 100%;
		margin-top: 10upx;
	}

	.address-name {
		font-size: 40upx;
		font-family: PingFang SC;
		font-weight: 800;
		color: #333333;
		text-overflow: ellipsis;
		white-space: nowrap;
		overflow: hidden;
		display: block;
		width: 100%;
	}

	.oi-header,
	.oi-deliver,
	.oi-goods,
	.oi-fee,
	.oi-total,
	.oi-orther-detail {
		background: #FFFFFF;
		padding: 30rpx 5%;
		margin-bottom: 15rpx;
		border-radius: 20rpx;

	}


	.oi-header .oi-order-status {
		font-size: 32rpx;
		font-weight: bold;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
	}

	.oi-header .oi-thank {
		color: #666666;
		font-size: 24rpx;
	}

	.oi-thank {
		padding: 5upx 0 5upx 0;
	}

	.oi-header .oi-order-btn {
		margin-top: 15rpx;
	}

	.oi-header .oi-order-btn text {
		padding: 10rpx 20rpx;
		margin-right: 15rpx;
		border-radius: 20rpx;
		border: solid 1px #dbdbdb;
		font-size: 28rpx;
		color: #999999;
	}

	.oi-header .oi-order-btn .order-btn-blue {
		background-color: #3589f7;
		color: #FFFFFF;
		border-radius: 20rpx;
	}

	.oi-deliver {
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
	}

	.oi-deliver .horseInfo .notice {
		color: #1270e0;
		font-size: 18rpx;
	}

	.oi-deliver .horseInfo .ps-ico {
		font-size: 20rpx;
		margin-left: 10rpx;
	}

	.oi-shop-info {
		display: flex;
		align-items: center;
	}

	.oi-deliver .call,
	.oi-shop-info .call {
		margin-left: auto;
	}

	.oi-goods .oi-shop-info {

		display: flex;
		flex-direction: row;
		justify-content: flex-start;
	}

	.oi-goods .oi-shop-info .oi-shop-logo {
		width: 60rpx;
		height: 60rpx;
		border-radius: 20upx;

	}

	.oi-goods .oi-shop-info .oi-shop-title {
		margin-left: 10rpx;
		font-weight: bold;
		font-size: 32upx;
		font-family: PingFang SC;
		font-weight: 800;
		color: #333333;
	}

	.oi-goods-list {
		margin-top: 40rpx;
	}

	.oi-goods-item {
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		margin-bottom: 20upx;
		margin-top: 20upx;
	}

	.oi-goods-item view {
		line-height: 1.2;
	}

	.oi-goods-item .goodsThumb {
		width: 100rpx;
		height: 100rpx;
		border-radius: 10rpx;
	}

	.oi-goods-item .goods-detail {
		margin-left: 10rpx;
		width: 65%;
	}

	.oi-goods-item .goods-detail .goodsName {
		width: 100%;
		font-weight: bold;
	}

	.oi-goods-item .goods-detail .goodsSpec text {
		font-size: 20rpx;
		margin-right: 15rpx;
		color: #666666;
	}

	.oi-goods-item .goods-detail .goodsNum {
		font-size: 20rpx;
		margin-top: 10rpx;
	}

	.oi-goods-item .goods-price {
		margin-left: auto;
		width: 15%;
		text-align: right;
	}

	.oi-goods-item .goods-price .markprice {
		font-size: 24rpx;
		margin-top: 15rpx;
		text-decoration: line-through;
		color: #666666;
	}

	.oi-fee-item {
		min-height: 80upx;
		align-items: center;
	}

	.oi-fee-item,
	.oi-orther-item {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		padding-bottom: 10rpx;
		font-size: 28rpx;
		width: 100%;
	}

	.oi-fee-item .minusfee {
		color: #FF3333;
	}

	.oi-total {
		text-align: right;
	}

	.oi-tit {

		white-space: nowrap;
	}

	.oi-total .total-prom {
		color: #666666;
		font-size: 24rpx;
	}

	.oi-total .total-price {
		font-weight: bold;
		margin-left: 10rpx;
	}

	.oi-orther-item {
		display: flex;
		justify-content: space-between;
	}

	.oi-orther-item view {
		text-align: right;
	}

	.oi-orther-item .tit {
		color: #666666;
		width: 20%;
	}

	.oi-orther-item .copy-btn {
		margin-left: auto;
	}

	/**orderSub**/
	.os-right-ico {
		width: 15rpx;
		height: 30rpx;
		/* margin-top: 20rpx; */
		margin-right: 10rpx;
	}

	.os-right-ico-small {
		width: 10rpx;
		height: 20rpx;
	}

	.os-time-ico {
		width: 30rpx;
		height: 30rpx;
	}

	.os-nav {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
	}

	.os-nav view {
		text-align: center;
		width: 50%;
		height: 80upx;
		background: #F7F7F7;
		padding: 10rpx 0rpx;
		border-radius: 20rpx;
	}

	.os-nav .hov {
		background: #1270e0;
		color: #FFFFFF;
	}

	.os-outward,
	.os-self {
		display: none;
	}

	.os-active {
		display: block;
	}

	.os-add-address {
		border: 1rpx solid #CCCCCC;
		border-radius: 10rpx;
		width: 200rpx;
		font-size: 25rpx;
		height: 60upx;

		text-align: center;
		color: #666666;
		margin: 5% auto;
		padding: 10rpx 0rpx;
	}

	.os-address {
		display: flex;
		padding: 25rpx 0 15rpx 0;
		font-size: 24rpx;
		justify-content: space-between;
	}

	.addr-address-item1 view {
		width: 100%;
		height: 40%;
		display: flex;
		align-items: center;
		line-height: 1.5;

	}

	.address {
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
		width: 100%;
	}

	.is_default {
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
		width: 100%;
	}

	.os-address .address {
		margin-left: 10rpx;
		display: flex;
		justify-content: space-between;
		width: 90%;
		align-items: center;
	}

	.os-address .address view {
		line-height: 1.2;
	}

	.os-address .forward,
	.os-time .forward {
		margin-left: auto;
	}


	.os-address .address .mobile {
		color: #666666;
		margin-left: 15rpx;
	}

	.os-time {
		display: flex;
		margin-top: 15rpx;
		padding-top: 15rpx;
		border-top: #EEEEEE solid 1px;
		font-size: 24rpx;
		justify-content: space-between;
	}

	.os-time .timeinfo {
		width: 100%;
		height: 80upx;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
	}

	.os-time .timeinfo .time-item {
		display: flex;
		justify-content: space-between;
		width: 90%;
		font-size: 28rpx;
	}


	.os-time .timeinfo .expect-time {
		font-size: 28rpx;
		color: #00A0DC;
		margin-left: 10rpx;
		line-height: 70rpx;
	}

	.os-self {
		padding-top: 25rpx;
	}

	.os-self-item {
		display: flex;
		font-size: 24rpx;
		border-bottom: 1rpx dashed #EEEEEE;
		padding: 10rpx;
		align-items: center;

	}

	.os-self-item:last-of-type {
		border: none;
	}

	.os-self-item .tit {
		width: 110rpx;
	}

	.os-self-item input {
		font-size: 24rpx;
		/* padding: 5rpx 15rpx; */
		width: 100%;
	}

	.os-pay {
		background: #FFFFFF;
		padding: 2%;
		margin-bottom: 15rpx;
		border-radius: 20rpx;
	}

	.os-pay view {
		background-color: #FFFFFF;
	}

	.os-pay .os-pay-item {
		display: flex;
		justify-content: space-between;
		line-height: 70rpx;
	}

	.os-pay .os-pay-item .pay-code {
		text-align: right;
		margin-top: 15rpx;
	}

	.os-pay .os-pay-item .pay-note {
		text-align: right;
		color: #999999;
		width: 85%;
		display: flex;
		justify-content: space-between;
		line-height: 75rpx;
	}

	.os-pay .os-pay-item .pay-note .notedetail {
		width: 95%;
		text-align: right;
		line-height: 75rpx;
	}

	.os-pay-ico {
		width: 60rpx;
		height: 60rpx;
		margin-right: 10rpx;
		margin-top: 5rpx;
	}

	.os-pay-left {
		display: flex;
	}

	.os-pay-list {
		background: #FFFFFF;
		width: 100%;
		margin: 0 auto;
		padding: 20rpx;
		border-radius: 15rpx;
		display: flex;
	}

	.os-pay-list .os-pay-item {
		width: 100%;
		position: relative;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		padding: 10rpx 0 15rpx 0;
		border-bottom: 1rpx solid #EEEEEE;
	}

	.os-pay-item:last-of-type {
		border: none;
	}

	.os-user-notice {
		background-color: #FFFFFF;
		border-radius: 20rpx;
		padding: 30rpx 5%;
	}

	.usernote {
		background: #F7F7F7;
		width: 100%;
		height: 200rpx;
		padding: 20rpx 0%;
		border-radius: 20rpx;
	}

	.usernote textarea {
		font-size: 24rpx;
		padding: 15rpx;
	}

	.position .loc-ico,
	.loc-ico {
		width: 30rpx;
		height: 36rpx;
		margin-top: 8rpx;
	}

	.nearby {
		padding-top: 25rpx;
	}

	.lab-tit {
		color: #666666;
		padding-left: 25rpx;
		font-size: 24rpx;
	}

	.os-sub-box {
		position: fixed;
		bottom: 1vh;
		width: 100%;
		z-index: 99;
		display: flex;
		justify-content: space-between;
		background: #F7F7F7;
		height: 90rpx;
		border-top: 1rpx solid #EEEEEE;
	}

	.os-sub-box .sub-amount {
		width: 65%;
		line-height: 90rpx;
		text-align: right;
	}

	.os-sub-box .sub-btn {
		width: 30%;
		text-align: center;
		background: #1270e0;
		line-height: 90rpx;
		height: 90rpx;
		color: #FFFFFF;
	}

	.v-block {
		height: 90rpx;
	}

	.oi-deduct {
		background: #F7F7F7;
		padding: 30rpx 5%;
		margin-bottom: 15rpx;
		border-radius: 20rpx;
	}

	.oi-deduct-item {
		min-height: 60upx;
		align-items: center;
		display: flex;
		justify-content: space-between;
	}

	.oi-deduct-item .minusfee {
		font-size: 24upx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #999999;
	}

	.oi-deduct-item .use-able {
		font-size: 24rpx;
	}

	.oi-deduct-item .coupon-rig {
		width: 24vw;
	}

	.oi-deduct-item .coupon-rig .coupon-num {
		background-color: #df3636;
		border-radius: 10px;
		padding: 8rpx 20rpx;
		color: #FFFFFF;
		font-size: 24rpx;
		margin-right: 2vw;
	}

	.os-self-tit {
		width: 120rpx;
	}


	.oi-deduct {
		background: #FFFFFF;
		margin-bottom: 15rpx;
	}

	.addr-address-item1 view {
		width: 100%;
		height: 40%;
		display: flex;
		align-items: center;
	}

	.oi-deduct-item {
		margin-top: 15rpx;
		display: flex;
		justify-content: space-between;
	}

	.oi-deduct-item .minusfee {
		color: #FF0000;
		font-size: 24rpx;
	}

	.oi-deduct-item .use-able {
		font-size: 24rpx;
	}

	.coupon-cancel {
		width: 640rpx;
		background: #FFFFFF;
		text-align: center;
		height: 60rpx;
		line-height: 60rpx;
		margin-top: 15rpx;

	}

	.note-tip {
		width: 100%;
		height: 100%;
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #999999;
	}

	.sub-coupon-list {
		background: #FFFFFF;
		height: 780rpx;
		width: 640rpx;
		padding: 0;
	}

	.os-self-tit {
		width: 120rpx;
	}

	checkbox-group {
		display: inline !important;
	}

	.os-add-addr-btn {
		background-color: #1270E0;
		color: #FFFFFF;
		border-radius: 20rpx;
		text-align: center;
		padding: 3%;
		width: 80%;
		margin: 0 auto;
	}

	.sub-pay-box {
		padding: 0% 3% 0 3%;
		display: flex;
		align-items: center;
		width: 94%;
		height: 100upx;
		margin-left: 3%;
		position: fixed;
		bottom: 2vh;
		z-index: 99;
		display: flex;
		flex-direction: row;
		background: #FFFFFF;
		box-shadow: 0px 0px 10upx 0px rgba(0, 0, 0, 0.05);
		border-radius: 20upx;
		position: absolute;
	}

	.zhifu {
		position: absolute;
		float: right;
		right: 3%;
		width: 32%;
	}

	.os-pay-left {
		display: flex;
		align-items: center;

	}

	.paySelect {
		position: absolute;
		float: right;
		right: 0;
	}

	.time-item-tit {
		display: flex;
		align-items: center;
		font-size: 28upx;
		font-family: PingFang SC;
		font-weight: 800;
		color: #333333;
	}

	.consigneebox {
		display: flex;
		flex-wrap: wrap;
		width: 100%;
		color: #999999;

	}

	.consignee {
		margin-right: 20upx;
		max-width: 100%;
		white-space: normal;
		word-wrap: break-word;
		line-height: 1.2;


	}

	.mobile {
		max-width: 100%;

	}

	/**** addressList *****/
	.addr-address-list {
		width: 90%;
		margin-left: 5%;
	}

	.addr-address-box {
		margin-top: 15upx;
		display: flex;
		justify-content: space-between;
		width: 100%;
		padding: 0 3% 0 3%;
		min-height: 120upx;
		align-items: center;
		background-color: #FFFFFF;
		border-bottom: solid 1rpx #EEEEEE;
		box-shadow: 0px 0px 10upx 0px rgba(0, 0, 0, 0.05);
		border-radius: 20upx;
	}

	.addr-address-item {
		display: flex;
		justify-content: space-between;
		width: 100%;
		padding: 3% 0;
		height: 120upx;
		background-color: #FFFFFF;
		border-bottom: solid 1rpx #EEEEEE;
	}

	.addr-address-item1 {
		width: 85%;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: flex-start;
		/* white-space: nowrap;
		text-overflow: ellipsis;
		overflow: hidden; */
	}

	.addr-address-item2 {
		width: 10%;
		height: 100%;
	}

	.addr-address-item .consignee {
		font-size: 24rpx;
		color: #333333;
	}

	.addr-address-item .mobile {
		margin-left: 15rpx;
		font-size: 24rpx;
		color: #333333;
	}

	.addr-address-item .default {
		color: #000000;
		font-size: 20rpx;
		font-weight: bold;
		margin-left: 15rpx;
	}

	.addr-address-item:last-of-type {
		border: none;
	}

	.addr-add-btn {
		width: 100%;
		height: 90rpx;
		line-height: 90rpx;
		text-align: center;
		position: fixed;
		bottom: 0;
		background: #1270e0;
	}

	.is_default {
		font-size: 24rpx;
		font-weight: bold;
		margin-left: 15rpx;
		color: #1270e0;
	}

	.detailimg {
		position: absolute;
		bottom: 210upx;

	}

	.gDetail-info {
		position: absolute;
		z-index: 1;
		min-height: 150upx;
		bottom: 0;
		background-color: white;
	}

	.oi-shouhuo {
		width: 40%;
		text-align: left;
		display: flex;
		align-items: center;
	}

	.s-prom-label-list {
		max-height: 80rpx;
		overflow: hidden;
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		flex-wrap: wrap;
	}

	.s-prom-label-list text {
		border: solid 1px #ffe6e6;

		font-family: PingFang-SC-Medium;
		font-size: 11px;
		font-weight: normal;
		font-stretch: normal;
		letter-spacing: 0px;
		color: #fe4646;
		padding: 3rpx 5rpx;
		border-radius: 5rpx;
	}


	.tag_zidingyi {
		background-color: #df3636;
		border-radius: 35upx;
		padding: 8rpx 20rpx;
		color: #FFFFFF;
		font-size: 24rpx;
		margin-right: 2vw;
	}

	.dizhi-info {
		display: flex;
		flex-wrap: wrap;
	}

	.tit-box {
		padding: 10rpx 20rpx 10rpx 20rpx;
		background: #FFF0F0;
		border: 2upx solid #F4D5D5;
		border-radius: 10upx;
	}

	.tit-style {
		font-size: 32upx;
		font-family: PingFang SC;
		font-weight: 800;
		color: #333333;
	}

	.preview-box {
		width: 100vw;
		height: 100vh;
		flex-direction: column;
	}

	.preview-box image {
		height: calc((297*90vw)/210);
		width: 90vw;
	}
</style>
